package com.suifeng.mq.stock.controller;

import com.suifeng.mq.common.enums.Status;
import com.suifeng.mq.common.exception.NoStockException;
import com.suifeng.mq.common.utils.R;
import com.suifeng.mq.common.vo.StockGoodsLockVo;
import com.suifeng.mq.stock.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/stock")
public class StockController {

    @Autowired
    private StockService stockService;

    @PostMapping("/lock/order")
    R orderLockStock(@RequestBody StockGoodsLockVo lockVo){
        try {
            Boolean stock =  stockService.orderLockStock(lockVo);
            return R.ok();
        }catch (NoStockException e){
            return R.error(Status.NO_STOCK_EXCEPTION.getCode(),Status.NO_STOCK_EXCEPTION.getMessage());
        }
    }
}
